<?php 

/**
 * Displays the content of a single post
 *
 * @package WordPress
 * @subpackage Parea
 * @since 1.0
 * @version 1.0
 */

?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

	<?php edit_post_link( __( 'Edit this page' , 'parea' ), '<p>', '</p>' ); ?>	
		
	<header>
		<h1><?php the_title(); ?></h1>
		
    
		<div class="post-meta">
			<p>

        <span class="dashicons dashicons-location-alt"></span>
        <span class="meta-info span-author">
           <?php echo types_render_field( 'cidade' ); ?>
        </span>
        
        <span class="dashicons dashicons-category"></span>
        <span class="meta-info span-category">
          <?php echo get_the_term_list($post->ID, 'profissao')?>	
        </span> 

			</p>

    </div>

	</header>	

	<div class="content">
    <?php the_post_thumbnail('partners'); ?>

    <div class="info">
      <p>
        <span class="dashicons dashicons-location-alt"></span>
        <span><?php echo types_render_field( 'cidade' ); ?></span>
      </p>
      <p>      
        <span class="dashicons dashicons-email-alt"></span>
        <span><?php echo types_render_field( 'email' ); ?></span>
      </p>
      <p>     
        <span class="dashicons dashicons-phone"></span>
        <span><?php echo types_render_field( 'telefone' ); ?></span>
      </p>
    </div>
      

    <?php

    the_content(); 
    
    $vip = get_post_meta( get_the_ID(), 'wpcf-parceiro-vip' );
    // var_dump($vip); // saida igual a -> array(1) { [0]=> string(3) "Sim" } 

    $img = types_render_field( 'imagem', array(
      'output'  => 'raw'
    ) );
    $images = explode(' ', $img);

    //var_dump($img);
    // string(111) "http://parea.net/wp-content/uploads/2019/01/logo.jpg http://parea.net/wp-content/uploads/2019/01/generica3.jpeg" 
    //var_dump($images);
    // array(2) { [0]=> string(52) "http://parea.net/wp-content/uploads/2019/01/logo.jpg" [1]=> string(58) "http://parea.net/wp-content/uploads/2019/01/generica3.jpeg" } 

    // neste remove a extensão dp arquivo
    $withoutExt = preg_replace('/\\.[^.\\s]{3,4}$/', '', $images);
    //var_dump($withoutExt);
    // array(2) { [0]=> string(48) "http://parea.net/wp-content/uploads/2019/01/logo" [1]=> string(53) "http://parea.net/wp-content/uploads/2019/01/generica3" } 

    // pegar o enderedo informado no campo e formatar para o google
    $address = types_render_field( 'endereco' );
    $exclude = array( '<br />', ' ', '\n', '\r', '<p>', '</p>' );
    $clean_address = str_replace($exclude, '+', $address);

    if($vip[0] === 'Sim'):
  
    ?>

      <h2>Galeria de fotos</h2>
        <div class="photo-gallery">
          <?php // foreach( $images as $img): ?>
          <?php foreach( $images as $img): ?>
            <a href="<?php echo $img; ?>" class="thickbox col-xs-12 col-sm-4" rel="gallery-personal">
              <img src="<?php echo $img; ?>" alt="" class="img-responsive">
            </a>
          <?php endforeach; ?>
        </div>

        <h2>Mapa</h2>
        <iframe
          width="100%"
          height="450"
          frameborder="0" style="border:0"
          src="https://www.google.com/maps/embed/v1/place?key=AIzaSyB29yZ0gwWNWbkkNbZFc9OvCZ3K7-40Igo&q=<?php echo $clean_address; ?>" allowfullscreen>
        </iframe>

  <?php

    endif;

		wp_link_pages( array(
			'before'      => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'parea' ) . '</span>',
			'after'       => '</div>',
			'link_before' => '<span>',
			'link_after'  => '</span>',
			'pagelink'    => '<span class="screen-reader-text">' . __( 'Page', 'parea' ) . ' </span>%',
			'separator'   => '<span class="screen-reader-text">, </span>',
		) );

		?>

	</div>


</article>